package ynu.sxp.demoapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ynu.sxp.demoapp.entity.OrderDetailet;
import ynu.sxp.demoapp.service.OrderDetailetService;
import ynu.sxp.demoapp.common.Result;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/OrderDetailetController")
public class OrderDetailetController {

    @Autowired
    private OrderDetailetService orderDetailetService;

    // 创建订单明细
    @PostMapping("/createOrderDetailet")
    public Result<OrderDetailet> createOrderDetailet(@RequestBody OrderDetailet orderDetailet) {
        OrderDetailet createdOrderDetailet = orderDetailetService.createOrderDetailet(orderDetailet);
        return Result.success(createdOrderDetailet);
    }

    // 根据订单明细ID获取订单明细
    @GetMapping("/getOrderDetailetById")
    public Result<OrderDetailet> getOrderDetailetById(@RequestParam UUID odId) {
        OrderDetailet orderDetailet = orderDetailetService.getOrderDetailetById(odId);
        return Result.success(orderDetailet);
    }

    // 根据订单ID获取订单明细列表
    @GetMapping("/listOrderDetailetByOrderId")
    public Result<List<OrderDetailet>> listOrderDetailetByOrderId(@RequestParam UUID orderId) {
        List<OrderDetailet> orderDetailes = orderDetailetService.getOrderDetailesByOrderId(orderId);
        return Result.success(orderDetailes);
    }

    // 更新订单明细
    @PostMapping("/updateOrderDetailet")
    public Result<Void> updateOrderDetailet(@RequestBody OrderDetailet orderDetailet) {
        orderDetailetService.updateOrderDetailet(orderDetailet);
        return Result.success(null);
    }

    // 删除订单明细
    @DeleteMapping("/deleteOrderDetailet")
    public Result<Void> deleteOrderDetailet(@RequestParam UUID odId) {
        orderDetailetService.deleteOrderDetailet(odId);
        return Result.success(null);
    }
}